<?php
defined('INDEX') or die('Access is denied.');

$status = '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';

if(isset($_SESSION['login'])){
	$redirect = '/?q=overview';
}

if(isset($_POST['username'])){
	if($username == $config['username'] && md5($password) == $config['password']){
		$_SESSION['login'] = 1;
		$redirect = '/?q=overview';
	}
	else{
		$status = '<p id="error">' . AUTHENTICATION_FAILED . '</p>';
	}
}

include(INCLUDES . 'header.php');
?>
					<?php if(!isset($redirect)){ ?>
					<div id="title"><h2><?php echo LOGIN; ?></h2></div>
					<div style="clear:both;"></div>
						<?php echo $status; ?>
						<form id="frmLogin" action="/?q=login" method="post">
						<p><label for="username" id="form"><?php echo USERNAME; ?></label>
						<input type="text" name="username" id="username" value="<?php echo htmlentities($username); ?>" class="text" style="width:200px;" tabindex="1" /></p>
						<p><label for="password" id="form"><?php echo PASSWORD; ?></label>
						<input type="password" name="password" id="password" value="" class="text" style="width:200px;" tabindex="2" /></p>
						<p><a class="button" href="#" onclick="this.blur();document.getElementById('frmLogin').submit();"><span><?php echo PROCEED_TO_MY_ACCOUNT; ?></span></a></p>
						<div style="clear:both;"></div>
					</form>
					<?php } else{ ?>
					<div id="title"><h2><?php echo REDIRECTING; ?></h2></div>
					<p><?php echo str_replace('%redirect%', $redirect, LOGIN_SUCCESS); ?></p>
					<?php } ?>
<?php include(INCLUDES . 'footer.php'); ?>